import host from '@/utils/ipConfig.js'
// import store from '@/store'
function http(options) {
	return new Promise((resolve, reject) => {
		var setting = {
			url: host.javaServer + options.url,
			data: options.data,
			method: options.method.toUpperCase() || 'GET',
			timeout: 60000,
			header: {
				'content-type': 'application/json', // from data,
				// 'SessionId': store.getters.sessionId || ''
				// 'token': uni.getStorageSync('token_key') || '',
				// 'from-source': 'APP_ADMIN'
			},
			success(res) {
				if (res.data.code === 401) {
					uni.showModal({
						title: '温馨提示',
						content: res?.data?.msg || '登录失效',
						confirmText: '登录',
						success: function(res) {
							if (res.confirm) {
								console.log('确定')
								uni.removeStorageSync('changzhouSessionId')
								uni.reLaunch({
									url: '/pages/login/index'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				} else if (res.data.code !== '000000') {
					console.log(res?.data?.msg)
					uni.showToast({
						icon: 'none',
						title: res?.data?.msg || 'Error'
					})
				} else {
					resolve(res.data);
				}

			},
			fail(err) {
				console.log('err', err);
				uni.showToast({
					icon: 'none',
					title: '网络超时!'
				})
				reject(err);
			},
		}
		if (options.header) {
			setting.header = Object.assign(setting.header, options.header);
		}
		uni.request(setting);
	})
}

export default http;
